//============================================================================
// Name        : area.cpp
// Author      : dfoelber
//============================================================================

#include "physics/area.h"

/**
* Default constructor. Initializes everything to 0.
**/
Area::Area()
{
}

/**
* Constructor that fills in the values of the area.
* 
* @param x X coordinate
* @param y Y coordinate
* @param width Width of the area
* @param height Height of the area
**/
Area::Area( int x, int y, int width, int height )
{
	this->x = x;
	this->y = y;
	this->width = width;
	this->height = height;
}

/**
* Deconstructor
**/
Area::~Area()
{
}

/**
* Checks if the area defined by the parameters intersects with the area.
* 
* @param x X coordinate
* @param y Y coordinate
* @param width Width of the supplied area
* @param height Height of the supplied area
* @return If the supplied area intersects
**/
bool Area::Intersects( int otherX, int otherY, int otherWidth, int otherHeight )
{
	int xIntersect = x <= otherX ? x + width - otherX : otherX + otherWidth - x;
	int yIntersect = y <= otherY ? y + height - otherY : otherY + otherHeight - y;
	
	if( xIntersect >= 0 && yIntersect >= 0 )
	{
		return true;
	}
	
	return false;
}

/**
* Sets the size of the area.
* 
* @param width The new width
* @param height The new height
**/
void Area::SetSize( int width, int height )
{
	this->width = width;
	this->height = height;
}

/**
* Sets the position of the area.
* 
* @param x The new X coordinate
* @param y The new Y coordinate
**/
void Area::SetPosition( int x, int y )
{
	this->x = x;
	this->y = y;
}

/**
* Gets the current X coordinate.
* 
* @return The X coordinate
**/
int Area::GetX() const
{
	return x;
}

/**
* Gets the current Y coordinate.
* 
* @return The Y coordinate
**/
int Area::GetY() const
{
	return y;
}

/**
* Gets the current width.
* 
* @return The width
**/
int Area::GetWidth() const
{
	return width;
}

/**
* Gets the current height.
* 
* @return The height
**/
int Area::GetHeight() const
{
	return height;
}
